package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.common.Result;
import com.amsp.oa.oademo.entity.EmployeeLeave;
import com.amsp.oa.oademo.service.EmployeeLeaveService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/employee-leave")
@Api(tags = "员工休职申请接口")
public class EmployeeLeaveController {

    @Autowired
    private EmployeeLeaveService employeeLeaveService;

    @PostMapping("/save")
    @ApiOperation("保存休职申请")
    public Result<Boolean> save(@RequestBody EmployeeLeave employeeLeave) {
        return Result.ok(employeeLeaveService.saveOrUpdate(employeeLeave));
    }

    @PostMapping("/batch-save")
    @ApiOperation("批量保存休职申请")
    public Result<Boolean> batchSave(@RequestBody List<EmployeeLeave> records) {
        return Result.ok(employeeLeaveService.saveOrUpdateBatch(records));
    }

    @GetMapping("/list")
    @ApiOperation("获取休职申请列表")
    public Result<IPage<EmployeeLeave>> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String employeeName,
            @RequestParam(required = false) String employeeId,
            @RequestParam(required = false) String department) {
        return Result.ok(employeeLeaveService.getPage(current, size, employeeName, employeeId, department));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取休职申请详情")
    public Result<EmployeeLeave> getById(@PathVariable Long id) {
        return Result.ok(employeeLeaveService.getById(id));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除休职申请")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.ok(employeeLeaveService.removeById(id));
    }
} 